function Core_Knowledge(gui, user, date, options, message) {
  this._gui = gui;
  this._user = user;
  this._date = date;
  this._options = options;
  this._message = message;
  
 
  this._createElements();
};

Core_Knowledge.prototype._createElements = function() {
  var _self = this;
  //Data
  this._base = (this._message[0] && this._message[0].d[0]) ? this._message[0].d[0] : pz_knowledge.instance();
  this._images = (this._message['img'] && this._message['img'].d) ? this._message['img'].d : [];


  //Display
  tinyMCE.init({
    // General options
    mode : "exact",
    elements : 'knowledge_detail_content',
    theme : "advanced",
    plugins : "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist",
    // Theme options
    theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
    theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
    theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
    theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_statusbar_location : "bottom",
    theme_advanced_resizing : true,
    
    file_browser_callback : 'filebrowser',

    // Example content CSS (should be your site CSS)
    content_css : "css/content.css",
    theme_advanced_font_sizes: "10px,12px,13px,14px,16px,18px,20px,22px,24px,26px,28px,30px",
    font_size_style_values : "10px,12px,13px,14px,16px,18px,20px,22px,24px,26px,28px,30px",
    width: '1000px',
    height: '500px',
    
    // Style formats
    style_formats : [
      {title : 'Bold text', inline : 'b'},
      {title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
      {title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
      {title : 'Example 1', inline : 'span', classes : 'example1'},
      {title : 'Example 2', inline : 'span', classes : 'example2'},
      {title : 'Table styles'},
      {title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
    ],

    // Replace values for the template plugin
    template_replace_values : {
      username : "Some User",
      staffid : "993210"
    }
  });
  
  var unique = 'know_base';
  
  var browse = document.createElement('span');
  var cancel = document.createElement('span');
  browse.id = unique + UploadUtils._defaultButtonPlaceholderId;
  cancel.id = unique + UploadUtils._defaultCancelButtonId;
  this._gui.upload.appendChild(browse);
  this._gui.upload.appendChild(cancel);
  
  var pos = DOMUtils.findPos(browse);
  var up = null;
  var initFunc = function() { var div = document.createElement('div');
                              var p = new ModulePopupBox();
                              p._open(div, { pos: [pos[0] + 100, pos[1] - 260], width: 468, t: '', doc: document }); 
                              up = new ModuleUpload(document, div, 468, 260, _self._user, _self._date, { u: unique, callbackFunc: function() { _self._updateElements(); }, popupBox: p });
                            };
  
  var uu = new UploadUtils(unique);
  uu._uploadUrl = 'custom/upload.php';
  uu._buttonImageUrl = 'custom/assets/upload/browse.png';
  uu._buttonWidth = 94;
  uu._buttonHeight = 29;
  uu._createInstance('knowledge/', {knowledge_trackId: this._base.track_id}, initFunc, function(file, result) { _self._images[_self._images.length] = result; up._callbackFunc(file, result); });
  
  this._gui.title.value = this._base.title;
  this._gui.title.onchange = function() { _self._base.title = this.value; };
  
  var tmps = KnowledgeType.array();
  for (var i = 0, il = tmps.length; i < il; i++) {
    var tmp = tmps[i];
    var op = new Option(tmp);
    this._gui.type.options[this._gui.type.options.length] = op;
    if (tmp == this._base.type) {
      this._gui.type.selectedIndex = this._gui.type.options.length - 1;
    }
  }
  if (tmps.length > 1) {
    this._base.type = this._gui.type.options[this._gui.type.selectedIndex].text;
    this._gui.type.onchange = function() { _self._base.type = this.options[this.selectedIndex].text; };
  }
  
  this._gui.intro_content.value = this._base.intro;
  this._gui.intro_content.onchange = function() { _self._base.intro = this.value; };
  this._gui.detail_content.appendChild(document.createTextNode(this._base.detail));
  
  //Submit
  this._gui.save.onclick = function() { _self._base.detail = tinyMCE.get('knowledge_detail_content').getContent();
                                        if (_self._images.length > 1) {
                                          window.alert('MORE THAN ONE IMAGE');
                                          return;
                                        }
                                        _self._base.link = (_self._images.length != 0) ? _self._images[0].link : '';
                                        new RequestUtils()._write(JSON.stringify([{ n: 'pz_knowledge', a: [_self._base], r: [] }]), function(result, params) { history.back(); }, { pos: DOMUtils.findPos(this) });
                                      };
  this._gui.back.onclick = function() { history.back(); };
  
  this._updateElements();
};

Core_Knowledge.prototype._updateElements = function() {
  var _self = this;
  DOMUtils.removeChildElements(this._gui.image);
//  var img = document.createElement('img');
//  img.style.width = '120px';
//  img.style.height = '120px';
//  img.src = 'http://{{$smarty.const.DOMAIN|escape:'javascript'}}{{$smarty.const.PATH|escape:'javascript'}}' + 'custom/' + this._base.link;
//  this._gui.image.appendChild(img);
  
  var table = document.createElement('table');
  this._gui.image.appendChild(table);
  var td, div, img, span, p, size;
  for (var i = 0, il = this._images.length; i < il; i++) {
    var tmp = this._images[i];
    
    if (table.rows.length == 0)  {
      td = table.insertRow(-1).insertCell(-1);
    } else if (table.rows[table.rows.length - 1].cells.length < 5) {
      td = table.rows[table.rows.length - 1].insertCell(-1);
    } else {
      td = table.insertRow(-1).insertCell(-1);
    }
    
    td.align = 'left';
    td.width = '120px';
    td.height = '120px';
    td._item = tmp;
    p = new ModulePopupBoxSimpleTip();
    td.onmouseover = function() { var div = document.createElement('div');
                                  div.appendChild(document.createTextNode(this._item.name + ', ' + this._item.size / 1000 + 'KB'));
                                  var pos = DOMUtils.findPos(this)
                                  p._open(div, { pos: [pos[0] + 100, pos[1] + 100 ] });
                                };
    td.onmouseout = function() { p._close(); }; 
    size = MiscUtils.decrease([tmp.width, tmp.height], [100, 100]);
    img = document.createElement('img');
    img.width = size[0];
    img.height = size[1];
    img.src = 'http://{{$smarty.const.DOMAIN|escape:'javascript'}}{{$smarty.const.PATH|escape:'javascript'}}' + 'custom/' + tmp.link;
    td.appendChild(img);
    div = document.createElement('div');
    div.appendChild(document.createTextNode(MiscUtils.filename(tmp.name, 12)));
    img = document.createElement('img');
    img.style.cursor = 'pointer';
    img.style.margin = '0 5px';
    img.src = 'image/delete.png';
    img._item = tmp;
    img.onclick = function() { var item = this._item;
                               new RequestUtils()._custom('delete', JSON.stringify(item), function(result, params) { if (result) { 
                                                                                                                       MiscUtils.remove(_self._images, item, 'track_id');
                                                                                                                       _self._updateElements(); 
                                                                                                                     } 
                                                                                                                   }, { pos: DOMUtils.findPos(this), php: 'custom/server.php' }); 
                             };
    div.appendChild(img);
    td.appendChild(div);
  }
};